<!-- eslint-disable vue/multi-word-component-names -->
<template>
    <div class="login_container">
        <div class="login_box">
            <div class="avatar_box">
                <img src="../assets/图片1.png" alt="">
            </div>
            <!-- 登录表单区域 -->
            <el-form ref="login_form_ref" :model="login_form" :rules="login_form_rules" label-width="0px" class="login_form">
                <!-- 用户名 -->
                <el-form-item prop="username">
                    <el-input v-model="login_form.username" prefix-icon="iconfont icon-user"></el-input>
                </el-form-item >
                <!-- 密码 -->
                <el-form-item prop="password">
                    <el-input v-model="login_form.password" prefix-icon="iconfont icon-3702mima" type="password"></el-input>
                </el-form-item>
                <!-- 按钮 -->
                <el-form-item class="btns">
                    <el-button type="primary" @click="login">登录</el-button>
                    <el-button type="info" @click="login_form_reset">重置</el-button>                 
                </el-form-item>
            </el-form>
                        
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            //登录表单数据绑定对象
            login_form:{
                username:'user8391',
                password:'67601285'
            },
            login_form_rules:{
                //验证用户名是否合法
                username:[
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 3, max: 12, message: '用户名 3 到 12 个字符', trigger: 'blur' }
                ],
                //验证密码是否合法
                password:[
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 6, max: 15, message: '密码 3 到 12 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        //重置登录表单
        login_form_reset(){
            this.$refs.login_form_ref.resetFields();
        },
        //登录验证
        login(){
            this.$refs.login_form_ref.validate(async valid=>{
                if(!valid) return;
                const {data} =await this.$http.post('/user',this.login_form);
                console.log (data);
                if(data.code !==1) return this.$message.error('登录失败');
                this.$message.success('登录成功');
                
                window.sessionStorage.setItem('data',data.data);
                this.$router.push("/home");
            });
        }
    }
}
</script>

<style lang="less" scoped>
.login_container {
    /* 使用 cover 属性值来调整背景图片的尺寸和裁剪 */
    background: url('https://th.bing.com/th/id/R.d742d8f3173ff51cf523862a91073913?rik=fdr5bwZnFTOeMg&riu=http%3a%2f%2fimg.zcool.cn%2fcommunity%2f01cd34574405ce6ac725550b683178.gif&ehk=Wu%2bjfO43ihXGArM2AQ7F5P3Jh1ClnvuIwrjEAbOywcQ%3d&risl=&pid=ImgRaw&r=0');
    background-size: cover;
    background-repeat: no-repeat;
    height: 100vh; /* 使用视窗高度来铺满整个页面 */
}
.login_box{
    width: 450px;
    height: 300px;
    background-color: rgba(255, 255, 255, 0.1); /* 设置背景颜色为半透明的白色 */
    border-radius: 3px;
    position: absolute;
    left: 70%;
    top: 50%;
    transform: translate(-50%, -50%);
  
    .avatar_box{
        height: 130px;
        width: 130px;
        border: 1px solid #eee;
        border-radius: 50%;
        padding: 10px;
        position: absolute;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: #fff;
        img{
            height: 100%;
            width: 100%;
            border-radius: 50%;
            background-color: #eee;
        }
    }
}
.login_form{
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 20px;
    box-sizing: border-box;
}
.btns{
    // 对齐按钮
    display: flex;
    justify-content: flex-end;
}
</style>
